// Behavior originally contributed by NiV.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Xml.Linq;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Profiles;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;


namespace Styx.Bot.Quest_Behaviors
{
    public class q30898 : CustomForcedBehavior
    {
        public q30898(Dictionary<string, string> args)
            : base(args)
        {
            try
            {
				QuestId=30898;
            }

            catch (Exception except)
            {
                // Maintenance problems occur for a number of reasons.  The primary two are...
                // * Changes were made to the behavior, and boundary conditions weren't properly tested.
                // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes.
                // In any case, we pinpoint the source of the problem area here, and hopefully it
                // can be quickly resolved.
                LogMessage("error", "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message
                                        + "\nFROM HERE:\n"
                                        + except.StackTrace + "\n");
                IsAttributeProblem = true;
            }
        }


        // Attributes provided by caller
        public int QuestId { get; private set; }

        // Private variables for internal state
        private bool _isBehaviorDone;
        private bool _isDisposed;
        private bool _isInitialized;
        private Composite _root;

        // Private properties
        private LocalPlayer Me { get { return (StyxWoW.Me); } }

        ~q30898()
        {
            Dispose(false);
        }

		public void Dispose(bool isExplicitlyInitiatedDispose)
        {
            if (!_isDisposed)
            {
                // NOTE: we should call any Dispose() method for any managed or unmanaged
                // resource, if that resource provides a Dispose() method.

                // Clean up managed resources, if explicit disposal...
                if (isExplicitlyInitiatedDispose)
                {
                    // empty, for now
                }

                // Clean up unmanaged resources (if any) here...
                TreeRoot.GoalText = string.Empty;
                TreeRoot.StatusText = string.Empty;

                // Call parent Dispose() (if it exists) here ...
                base.Dispose();
            }

            _isDisposed = true;
        }

        #region Overrides of CustomForcedBehavior

        protected override Composite CreateBehavior()
        {
            return _root ?? (_root =
                new PrioritySelector(
						
						new Decorator(ret => true,
							new Sequence(
								new Action(c =>
								{
									Lua.DoString("CastPetAction({0})", 1);
									StyxWoW.SleepForLagDuration();
									SpellManager.ClickRemoteLocation(new WoWPoint(1217.66, 2816.24, 263.65));
									StyxWoW.SleepForLagDuration();
									Thread.Sleep(2000);
								}),
								new Action(c =>
								{
									Lua.DoString("CastPetAction({0})", 1);
									StyxWoW.SleepForLagDuration();
									SpellManager.ClickRemoteLocation(new WoWPoint(1221.926, 2858.376, 265.3132));
									StyxWoW.SleepForLagDuration();
									Thread.Sleep(2000);
								}),
								new Action(c =>
								{
									Lua.DoString("CastPetAction({0})", 1);
									StyxWoW.SleepForLagDuration();
									SpellManager.ClickRemoteLocation(new WoWPoint(1196.79, 2878.34, 284.15));
									StyxWoW.SleepForLagDuration();
									Thread.Sleep(2000);
								}),
								new Action(c =>
								{
									Lua.DoString("CastPetAction({0})", 1);
									StyxWoW.SleepForLagDuration();
									SpellManager.ClickRemoteLocation(new WoWPoint(1216.11, 2799.85, 264.61));
									StyxWoW.SleepForLagDuration();
									Thread.Sleep(2000);
								})
							)
						)
				
                    ));
        }


        public override void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }


        public override bool IsDone
        {
            get
            {
                return (_isBehaviorDone     // normal completion
                        || !UtilIsProgressRequirementsMet(QuestId, QuestInLogRequirement.InLog, QuestCompleteRequirement.NotComplete));
            }
        }


        public override void OnStart()
        {
            // This reports problems, and stops BT processing if there was a problem with attributes...
            // We had to defer this action, as the 'profile line number' is not available during the element's
            // constructor call.
            OnStart_HandleAttributeProblem();

            // If the quest is complete, this behavior is already done...
            // So we don't want to falsely inform the user of things that will be skipped.
            if (!IsDone)
            {
                PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById((uint)QuestId);

                TreeRoot.GoalText = GetType().Name + ": " + ((quest != null) ? ("\"" + quest.Name + "\"") : "In Progress");
            }
        }

        #endregion
    }
}
